# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponse
import itchat
import time
from itchat.content import TEXT

def index(request):
    return render(request, 'home.html')


#manage
def admin_index(request):
    return render(request, 'index.html')


def admin_login(request):
    return render(request, 'login.html')


def admin_main(request):
    return render(request, 'main.html')


#robot
def robot_index(request):
    return render(request, 'robot_index.html')


def robot_start(request):
    uuid = itchat.get_QRuuid()
    qr_code = './runtime/image/qr/' + 'qr_code' + '.png'
    qrStorage = itchat.get_QR(picDir=qr_code)
    # qr_code = './runtime/image/qr/' + 'qr_code' + '.png'
    # itchat.auto_login(picDir=qr_code)
    # robot_id = itchat.get_QRuuid()

    robot_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # hotReload=True（修改程序不用多次扫码），我们使用热启动
    # itchat.auto_login()
    data = {
        'robot_id': 1,
        'qr_code': uuid,
        'robot_start_time': robot_start_time
    }
    return render(request, 'robot_wx_login.html', {'code': 200, 'msg': '', 'data': data})


#测试用
def test(request):
    return render(request, 'form.html')


def add(request):
    a = request.GET['a']
    b = request.GET['b']
    a = int(a)
    b = int(b)
    return HttpResponse(str(a + b))